package com.attilax.hre;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.reflect.ConstructorUtils;
import org.apache.commons.lang3.reflect.MethodUtils;

 





import aaaCfg.IocX4nodb;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;

import com.attilaax.encode.EncodeX;
import com.attilax.core;
import com.attilax.lang.ParamX;
 
import com.attilax.lang.net.WebBrowser;
import com.attilax.ref.refx;

@Deprecated
public class UrlDslParser4web {

//	private WebBrowser webBrowser;
//
//	public UrlDslParser4web(WebBrowser webBrowser) {
//		this.webBrowser = webBrowser;
//	}
	
	public UrlDslParser4web() {
		// TODO Auto-generated constructor stub
	}
	 
	@SuppressWarnings("all")
	public String exe(HttpServletRequest req) {
		
		String ver=req.getParameter("ver");
		if(ver!=null && ver.trim().equals( "2"))
		{
			IocX4nodb.db.set(req.getParameter("db"));
			return new UrlDslParserV2().exe(req);
		}
	
	//	Map req = new ParamX().urlParams2Map((String) parameters);
 
		String meth = (String) req.getParameter("$method");
		//$method=aaaCms.CmsImpLocalFileVer.list&
		//$callback=cate_click_callback&http_param=select++*+from+gv_material+where+material_type+%3D+6 order+by++convert%28material_description+using+gbk%29 
		//&param=6
		String classname = refx.getClassName(meth);

		String meth_name = refx.getMethodName(meth);
		String callback_fun = (String) req.getParameter("$callback");

		Object o;

		try {
			 
			o = ConstructorUtils.invokeConstructor(

			Class.forName(classname), null);
			Object invokeMethod_ret = MethodUtils.invokeMethod(o, meth_name,
					req);
			String ret="";
			if(  invokeMethod_ret   instanceof String)
			  ret = (String) invokeMethod_ret;
			else
				ret=core.toJsonStrO88(invokeMethod_ret);
			 return ret;
		} catch (Throwable e) {
			String ret="";
			ret=core.toJsonStrO88(e);
			 return ret;
		 

		}
//		RuntimeException re = new RuntimeException("calljava.refImp() err ");
//		String string = EncodeX.jsEncodeSingleQuoue(core.toJsonStrO88(re));
//		webBrowser.executeJavascript(callback_fun + "('" + string + "')");
		// return core.toJsonStrO88(new
		// RuntimeException("calljava.refImp() err ") );

	}
//
//	private Object refImp(String meth, List li) {
//		String classname = refx.getClassName(meth);
//
//		String meth_name = refx.getMethodName(meth);
//
//		Object o;
//
//		try {
//			o = ConstructorUtils.invokeConstructor(
//
//			Class.forName(classname), null);
//			return MethodUtils.invokeMethod(o, meth_name, li.get(0));
//		} catch (NoSuchMethodException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (Exception e) {
//
//			return core.toJsonStrO88(e);
//
//		}
//
//		return core
//				.toJsonStrO88(new RuntimeException("calljava.refImp() err "));
//
//	}

}
